package io.xxx.mario.robot.convert;

import io.xxx.mario.robot.Robot;
import io.xxx.mario.robot.api.SaveRobotRequest;
import org.springframework.beans.BeanUtils;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class SaveRobotRequestConverter implements Converter<SaveRobotRequest, Robot> {

    @Override
    public Robot convert(@NonNull SaveRobotRequest source) {
        Robot robot = new Robot();
        BeanUtils.copyProperties(source, robot);
        robot.setJoinedRoomCount(0);
        robot.setLeavedRoomCount(0);
        robot.setEnabled(false);
        LocalDateTime now = LocalDateTime.now();
        robot.setCreatedTime(now);
        robot.setUpdatedTime(now);
        return robot;
    }
}
